package cn.itsource.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.IdUtil;
import cn.itsource.pojo.app.dto.AddCarDto;
import cn.itsource.pojo.domain.CustomerCar;
import cn.itsource.mapper.CustomerCarMapper;
import cn.itsource.service.ICustomerCarService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 客户车辆 服务实现类
 * </p>
 *
 * @author beishan
 * @since 2024-03-25
 */
@Service
public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, CustomerCar> implements ICustomerCarService {

    @Autowired
    private CustomerCarMapper customerCarMapper;


    /**
     * 车辆列表
     * @return
     */
    @Override
    public List<CustomerCar> carList() {
        return super.list(new LambdaQueryWrapper<CustomerCar>().eq(CustomerCar::getCustomerId, StpUtil.getLoginIdAsLong()));
    }

    /**
     * 添加车辆
     */
    @Override
    public void addCar(AddCarDto addCarDto) {
        CustomerCar customerCar = new CustomerCar();
        long id = IdUtil.createSnowflake(1, 1).nextId();

        customerCar.setId(id);
        customerCar.setCustomerId(StpUtil.getLoginIdAsLong());
        customerCar.setCarPlate(addCarDto.getCarPlate());
        customerCar.setCarType(addCarDto.getCarType());
        super.save(customerCar);
    }
}
